#ifndef OHOS_RIVE_FILE_ASSET_LOADER_H
#define OHOS_RIVE_FILE_ASSET_LOADER_H

#include "../../include/helpers/render_type.h"
#include "rive/assets/audio_asset.hpp"
#include "rive/assets/font_asset.hpp"
#include "rive/assets/image_asset.hpp"
#include "rive/factory.hpp"
#include "rive/file_asset_loader.hpp"
#include <napi/native_api.h>

namespace ohos_rive {
class FileAssetLoader : public rive::FileAssetLoader {
public:
    FileAssetLoader(napi_env env, napi_value jsObject);
    ~FileAssetLoader() override;

    bool loadContents(rive::FileAsset &asset, rive::Span<const uint8_t> inBandBytes, rive::Factory *factory) override;

    void setRendererType(RendererType rendererType);
    RendererType getRendererType() const;
    napi_env GetEnv() const;

private:
    static napi_value MakeJsAsset(napi_env env, rive::FileAsset &asset, RendererType rendererType);
    static napi_value CreateByteArray(napi_env env, rive::Span<const uint8_t> data);

    napi_env m_env;
    napi_ref m_jsFileAssetLoaderRef = nullptr;
    napi_ref m_jsLoadContentsMethodRef = nullptr;
    RendererType m_rendererType = RendererType::None;
};
} // namespace ohos_rive

#endif // OHOS_RIVE_FILE_ASSET_LOADER_H
